Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implementation of token transfer (ICS20) contract #24

Merged
merged 16 commits into from
Jul 30, 2024

Conversation

Farhad-Shabani
Copy link
Member

@Farhad-Shabani Farhad-Shabani commented Jul 23, 2024

Closes: #21

Description

We initially planned to write a simple ICS20 contract with basic operations to familiarize ourselves with the essentials. However, as I added more elements, it evolved into a full ICS20 token transfer contract. This first version isn't perfect and might not have the best design choices, but it serves as a solid first iteration. It sets the stage for team discussions and helps us nail down the details as we move forward.

Components

This PR includes the following components. In Cairo contracts, a component is like a reusable building block that can be combined with others to create a smart contract with all the needed features.

  • ICS20TransferComponent: Handles ICS20 token transfers.
  • TransferrableComponent: Allows the Transfer contract to control sending and receiving tokens.
  • ERC20MintableComponent: Adds mintable / burnable features to a regular ERC20 contract, making the total supply flexible for IBC contracts.
  • IBCGovernanceComponent: Allows a governance to update specific IBC states, especially for contract upgrades and setting ERC20 class hashes. The current implementation is basic and aims to show how it connects with other components.

Preset Contracts

By using the above components and a few others from the OpenZeppelin repository, two contracts have been implemented:

  • ERC20: An extended ERC20 contract with mintable capabilities for a flexible total supply.
  • Transfer: The contract for IC20 token transfer.

Unit Tests

The following tests cover the happy path for when a MsgTransfer or recv Packet is submitted to the Transfer contract. Further tests, particularly to catch faulty scenarios, can be added in a subsequent PR.

  • test_escrow_unescrow_roundtrip
  • test_mint_burn_roundtrip

Scripts

  • Contract deployment steps
  • Contract invocation steps

CI Job

  • Contract tests are included

Highlights

  • Verifying ByteArray is quite expensive. We need to find the most efficient way to verify string-like variables. For example, identifiers such as PortId and ChannelId, which are strings in IBC, must be checked to ensure they meet specifications. Deciding on the best approach will finalize the argument types for some contract APIs.

TODO

  • Conduct a self-review
  • Specify the key computation algorithm
  • Update invoke.sh

@Farhad-Shabani Farhad-Shabani changed the title feat: Initial implementation of token transfer (ICS20) contract feat: implementation of token transfer (ICS20) contract Jul 30, 2024
@Farhad-Shabani Farhad-Shabani marked this pull request as ready for review July 30, 2024 05:50
@soareschen
Copy link
Collaborator

I'll merge this first to minimize merge conflicts. we can review it synchronously later.

@soareschen soareschen merged commit 656103f into main Jul 30, 2024
3 checks passed
@soareschen soareschen deleted the farhad/ics20-impl branch July 30, 2024 09:10

// Note: if bytes has leading `\0` (null char), `felt252` forgets that information.
// bytes_to_felt252(felt252_to_bytes(x)).unwrap() == x
pub fn bytes_to_felt252(bytes: @ByteArray) -> Option<felt252> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use the hash methods provided by Cairo to hash the byte array? https://book.cairo-lang.org/ch11-04-hash.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out. I tried it in #38. It perfectly works. Way cheaper than those functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Initial implementation of IBC transfer escrow contract for Starknet
3 participants